package com.sprouting.ops.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sprouting.ops.annotations.invoke.IdempotentSingle;
import com.sprouting.ops.interfaces.AddGroup;
import com.sprouting.ops.interfaces.ConstantBase;
import com.sprouting.ops.interfaces.UpdGroup;
import com.sprouting.ops.model.OpsSiteTimeLine;
import com.sprouting.ops.model.ResultJson;
import com.sprouting.ops.model.qo.OpsSiteTimeLineQo;
import com.sprouting.ops.service.OpsSiteTimeLineService;
import com.sprouting.ops.utils.CheckTool;
import com.sprouting.ops.utils.EntityTool;
import com.sprouting.ops.utils.IdTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 场所项目时间轴(OpsSiteTimeLine)(OPS_SITE_TIME_LINE) 表控制层
 *
 * @author ：lx（长沙麓谷）
 * @date 创建时间：2025-08-20 21:41:14
 */
@Slf4j
@RestController
@RequestMapping("opsSiteTimeLine")
public class OpsSiteTimeLineController {

    @Resource
    private OpsSiteTimeLineService opsSiteTimeLineService;




    /**
     * 分页查询场所项目时间轴
     * @param query 查询参数
     * @return
     */
    @PostMapping("getListPage")
    public ResultJson getListPage(OpsSiteTimeLineQo query){
        Page page = query.getPage();
        return ResultJson.success(opsSiteTimeLineService.getListPage(page, query));
    }

    /**
     * 删除场所项目时间轴
     * @param id 场所项目时间轴id
     * @return
     */
    @PostMapping("delOpsSiteTimeLine")
    @IdempotentSingle
    public ResultJson delOpsSiteTimeLine(String id){
        if (CheckTool.checkNull(id)){
            return ResultJson.errorCheck();
        }

        opsSiteTimeLineService.removeById(id);
        return ResultJson.success();
    }

    /**
     * 更新场所项目时间轴
     * @param bo 修改参数
     * @return
     */
    @PostMapping("updOpsSiteTimeLine")
    @IdempotentSingle
    public ResultJson updOpsSiteTimeLine(@Validated(UpdGroup.class) OpsSiteTimeLine bo){
        String msg = checkOpsSiteTimeLine(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }

        EntityTool.updBase(bo);
        opsSiteTimeLineService.updateById(bo);
        return ResultJson.success(bo);
    }

    /**
     * 保存场所项目时间轴
     * @param bo 保存参数
     * @return
     */
    @PostMapping("saveOpsSiteTimeLine")
    @IdempotentSingle
    public ResultJson saveOpsSiteTimeLine(@Validated(AddGroup.class) OpsSiteTimeLine bo){
        String msg = checkOpsSiteTimeLine(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }
        if (bo.getLevel() == null){
            bo.setLevel(ConstantBase.TimeLineLevel.ORDINARY);
        }

        bo.setId(IdTool.getId());
        EntityTool.saveBase(bo);
        opsSiteTimeLineService.save(bo);
        return ResultJson.success(bo);
    }


    /**
     * 场所项目时间轴数据校验
     * @param bo 场所项目时间轴 校验数据
     * @return 非null则有错误
     */
    private String checkOpsSiteTimeLine(OpsSiteTimeLine bo){

        return null;
    }

}
